<template>
  <div class="connect">
    <el-button class="elbtn" @click="connectMsg">连接设备</el-button>
    <el-button class="elbtn" @click="closeWs">关闭设备</el-button>
  </div>
</template>

<script setup lang="ts">
import { closeWebSocket, initWebSocket } from '@/utils/websocket'
import userStore from '@/store'

const { useWebsocketStore } = userStore()

//连接设备  （具体路径和后端规定）
function connectMsg() {
  const toIp = `ws://localhost:3000/basic`;
  useWebsocketStore().setConnected(true)
  initWebSocket(toIp)
}

// 设备断开
function closeWs() {
  closeWebSocket()
  useWebsocketStore().setConnected(false)
}
</script>

<style scoped></style>